<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:include="common/admin-header"></head>

<body class="app sidebar-mini rtl">
<div th:include="common/admin-sadbar"></div>

<main class="app-content">
    <div class="app-title">
        <div>
            <h1><i class="fa fa-th-list"></i> 用户列表</h1>
            <p>Table to display analytical data effectively</p>
        </div>
        <ul class="app-breadcrumb breadcrumb side">
            <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
            <li class="breadcrumb-item">Tables</li>
            <li class="breadcrumb-item active"><a href="/admin/users">用户列表</a></li>
        </ul>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="tile">
                <div class="tile-body">
                    <table class="table table-hover table-bordered" style="white-space: nowrap" id="sampleTable">
                        <thead>
                        <tr>
                            <th th:class="text-center">用户ID</th>
                            <th th:class="text-center">邮箱</th>
                            <th th:class="text-center">昵称</th>
                            <th th:class="text-center">注册时间</th>
                            <th th:class="text-center">账号类型</th>
                            <th th:class="text-center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="user:${users}">
                            <td><a th:text="${user.getUserId()}">id</a></td>
                            <td><a th:text="${user.getEmail()}">email</a></td>
                            <td th:text="${user.getNickName()}" th:class="text-center">user name</td>
                            <td th:text="${user.getRegistrationTime()}" th:class="text-center">time</td>
                            <div th:switch="${user.getIsAdmin()}">
                                <td th:case="true" th:class="text-center">管理员</td>
                                <td th:case="false" th:class="text-center">普通用户</td>
                            </div>


                            <td th:class="text-center">
                                <button id="removeUser" class="btn btn-sm btn-danger"
                                        th:onclick="removeUser([[${user.getUserId()}]])">删除用户
                                </button>
                            </td>
                        </tr>
                        </tbody>
                    </table>

                </div>
            </div>
        </div>
    </div>
</main>

<div th:include="common/script::script"></div>

<script type="text/javascript">$('#sampleTable').DataTable();</script>
<script>

    function removeUser(id) {
        bootbox.confirm({
            message: "确认删除吗？",
            buttons: {
                confirm: {
                    label: 'Yes',
                    className: 'btn-success'
                },
                cancel: {
                    label: 'No',
                    className: 'btn-danger'
                }
            },
            callback: function (result) {
                if (result) {
                    $.ajax({
                        url: "/flytest/user/admin/user?id=" + id,
                        type: 'delete',
                        dataType: 'json',
                        success: function (res) {
                            if (res.code === '200') {
                                window.location.href = '/flytest/user/admin';
                            }

                        }
                    });

                }
            }
        });
    }
</script>
</body>
</html>